#include <bits/stdc++.h>
using namespace std;

struct node{
    vector<int> car;
};

int t, n, m, l, vm;
const int N = 1e5 + 15, M = 1e5 + 15, L = 1e6 + 15, V = 1e3 + 15;
int d[N], v[N], a[N];
node binus[L];
bool mon[L];
bool cnt[N];
bool in[N];
bool del[M];
priority_queue<int> gate[M];
int ans1;
int ans2;
list<int> lst;
int p[M];

bool a_c_b(int a, int b){
    if (gate[a].size() >= gate[b].size()){
        priority_queue<int> t1 = gate[a];
        priority_queue<int> t2 = gate[b];
        while (!t2.empty()){
            int ta = t1.top(), tb = t2.top();
            t1.pop();
            t2.pop(); 
            if (ta != tb)
                return false;
        }
        return true;
    }else{
        return false;
    }
}


int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> t;
    while (t--){
        memset(d, 0, sizeof d);
        memset(v, 0, sizeof v);
        memset(a, 0, sizeof a);
        memset(binus, 0, sizeof binus);
        memset(mon, 0, sizeof mon);
        memset(cnt, 0, sizeof cnt);
        memset(in, 0, sizeof in);
        memset(del, 0, sizeof del);

        cin >> n >> m >> l >> vm;
        
        for (int i = 1; i <= n; i++){
            cin >> d[i] >> v[i] >> a[i];
            if (a[i] == 0){
                if (v[i] > vm){
                    binus[d[i]].car.push_back(i);
                    binus[l].car.push_back(i);
                }
            }
            if (a[i] < 0){
                if (v[i] > vm){

                    double sm = (vm * vm - v[i] * v[i]) * 1.0 / (2 * a[i] * 1.0);
                    // double s0 = (v[i] * v[i] * 1.0) / (2 * a * -1.0);
                    if (sm == (int)sm){
                        sm -= 1;
                    }
                    binus[d[i]].car.push_back(i);
                    binus[min((int)sm + d[i], l)].car.push_back(i);
                }
            }
            if (a[i] > 0){
                if (v[i] > vm){
                    binus[d[i]].car.push_back(i);
                    binus[l].car.push_back(i);
                }else{
                    double sm = (vm * vm - v[i] * v[i]) * 1.0 / (2 * a[i] * 1.0);
                    sm += d[i] + 1;
                    
                    if (sm <= l){
                        binus[(int)sm].car.push_back(i);
                        binus[l].car.push_back(i);
                    }
                    
                }
            }
        }
//////////////////////////////////////////////////////////////////////////////////////////
        
        
//////////////////////////////////////////////////////////////////////////////////////////
        for (int i = 1; i <= m; i++){
            cin >> p[i];
            mon[p[i]] = 1;
        }

        for (int i = 0; i <= l + 1; i++){
            bool bug[N] = {0};
            if (binus[i].car.size()){
                for (int j = 0; j < binus[i].car.size(); j++){
                    int u = binus[i].car[j];
                    if (in[u] == 0){
                        lst.push_back(u);
                        in[u] = 1;
                    }
                    else{
                        in[u] = 0;
                        bug[u] = 1;
                    }
                }
            }
        
            if (mon[i]){
                if (lst.empty())
                    continue;
                for (list<int>::iterator it = lst.begin(); it != lst.end(); it++){
                    if (!cnt[*it]){
                        ans1++;
                        cnt[*it] = 1;
                    }
                    gate[i].push(*it);
                }
            }
            if (binus[i].car.size()){
                for (int j = 0; j < binus[i].car.size(); j++){
                    int u = binus[i].car[j];
                    if (bug[u] == 1)
                        lst.remove(u);
                }
            }
        }
        cout << ans1 << ' ';
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        ans2 = 0;
        for (int i = 1; i <= m; i++){
            int tmp = 1;
            int u = p[i];
            while (u + tmp <= m){
                if (!del[u + tmp] and !del[u]){
                    if (a_c_b(u, u+ tmp)){
                        ans2++;
                        del[u + tmp] = 1;
                        tmp++;
                        continue;
                    }
                    if (a_c_b(u + tmp, u)){
                        ans2++;
                        del[u] = 1;
                        tmp++;
                        continue;
                    }
                    break;
                }
                tmp++;
            }
        }
        cout << ans2 << endl;
    }
    return 0;
}